package Ui;

/*
 * @author Paolo Cordova
 */

public class PieceDown extends PieceState 
{
	
	private static PieceDown INSTANCE = null;
	
	protected PieceDown()
	{

	}
	
	public static PieceDown Instance() 
	{
		if (INSTANCE == null) {
			INSTANCE = new PieceDown();
		}
		
		return INSTANCE;
	}
	
	public void move(final Piece piece, int currentSpace, int newSpace) 
	{
		assert(newSpace < 40);
		
		while(currentSpace != newSpace) {
					
			piece.pixelY_ = moveSquareDown(piece, piece.pixelX_, piece.pixelY_, 1);
					
			currentSpace = (currentSpace + 1) % 40;
			
			if (currentSpace == 0) {	
				piece.pixelY_ = moveSquareDown(piece, piece.pixelX_, piece.pixelY_, leftDownYBuffer);
				piece.pixelX_ = moveSquareLeft(piece, piece.pixelX_, piece.pixelY_, xBuffer);
				
				piece.changeState(PieceLeft.Instance());
				piece.getState().move(piece, currentSpace, newSpace);
				break;
			}
		}
	}
}